/*
 * Sets up the TableView for the Cats tab. Sets the title by the select query and pushes it to the window.
 */
var currentWin = Ti.UI.currentWindow;
var tableview = Ti.UI.createTableView({style:Titanium.UI.iPhone.TableViewStyle.GROUPED});
function setData(){
	var dbversion = 1.3;
	var db = Ti.Database.install('../paws.sqlite','cats' + dbversion);
	var rows = db.execute('SELECT name from cats where status=1');
	var dataArray = [];
	while (rows.isValidRow())
	{
		dataArray.push({title:'' + rows.fieldByName('name') + '', hasChild:true, path:'../paws/cats_ipad.js'});
		rows.next();
	}
	tableview.setData(dataArray);
}


tableview.addEventListener('click', function(e){
	if (e.rowData.path)
	{ 
		var win = Ti.UI.createWindow({
			url:e.rowData.path,
			title:e.rowData.title
		});
		var catName = e.rowData.title;
		win.CatName = catName;
		Ti.UI.currentTab.open(win);
	}
});
currentWin.add(tableview);
setData();
